<template>
	<view class="content">
		<view class="criter_bt">
			<view class="line"></view>
			<text>基本信息</text>
		</view>
		<view class="dec_main">
			<view class="dec_li dush_li">
				<view class="dec_le">
					<label>申请人员：</label>
				</view>
				<view class="dec_ri">
					<text>{{ jsonData.create_user }}</text>
				</view>
			</view>
			<view class="dec_li dush_li">
				<view class="dec_le">
					<label>所属部门：</label>
				</view>
				<view class="dec_ri">
					<text>{{ jsonData.apply_dept_name }}</text>
				</view>
			</view>
			<view class="dec_li">
				<view class="dec_le">
					<label>申报时间：</label>
				</view>
				<view class="dec_ri">
					<text>{{ jsonData.create_date }}</text>
				</view>
			</view>
		</view>
		<view class="criter_bt">
			<view class="line"></view>
			<text>检修信息</text>
		</view>
		<view class="dec_main">
			<view class="dec_li dec_flex">
				<view class="dec_le">
					<label>*检修类型：</label>
				</view>
				<view class="dec_ri">
					<text>{{ jsonData.overhaul_type_desc }}</text>
				</view>
			</view>
			<view class="dec_li dec_flex">
				<view class="dec_le">
					<label>*单据类型：</label>
				</view>
				<view class="dec_ri">
					<text>{{ jsonData.bill_type_desc }}</text>
				</view>
			</view>
			<view class="dec_li dec_flex">
				<view class="dec_le">
					<label>*施工类型：</label>
				</view>
				<view class="dec_ri">
					<text>{{ jsonData.build_type_desc }}</text>
				</view>
			</view>
			<view v-if="showBuild">
				<view class="dec_li dec_flex">
					<view class="dec_le">
						<label>*施工单位：</label>
					</view>
					<view class="dec_ri">
						<text>{{ jsonData.build_unit }}</text>
					</view>
				</view>
				<view class="dec_li dec_flex">
					<view class="dec_le">
						<label>*单位负责人：</label>
					</view>
					<view class="dec_ri">
						<text>{{ jsonData.build_person }}</text>
					</view>
				</view>
			</view>
			<view class="dec_li dec_flex" v-if="jsonData.fault_class != 2">
				<view class="dec_le">
					<label>*检修装置：</label>
				</view>
				<view class="dec_ri">
					<text>{{ jsonData.equipment_name }}</text>
				</view>
			</view>
			<view class="dec_li dec_flex">
				<view class="dec_le">
					<label>*检修设备：</label>
				</view>
				<view class="dec_ri">
					<text>{{ jsonData.device_name }}</text>
				</view>
			</view>
			<view class="dec_li dec_flex">
				<view class="dec_le">
					<label>*设备位号：</label>
				</view>
				<view class="dec_ri">
					<text>{{ jsonData.device_no }}</text>
				</view>
			</view>
			<view class="dec_li dec_flex">
				<view class="dec_le">
					<label>*工时：</label>
				</view>
				<view class="dec_ri">
					<text>{{ jsonData.work_hours }}</text>
				</view>
			</view>
			<view class="dec_li " v-if="jsonData.info_pics.length>0">
				<view class="dec_le">
					<label>拍照取证：</label>
				</view>
				<view class="dec_ri">
					<view class="pic-view">
						<view style="width: 70%; display: flex;">
							<view v-for="(jtem, j) in jsonData.info_pics" :key="j" style="margin: 10rpx;">
								<image :src="fileUrl + jtem.pic_url" class="detail_img" @click="previewImg(jsonData.info_pics, j)">
								</image>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="dec_li">
				<view class="dec_le">
					<label>*检修内容：</label>
				</view>
				<view class="dec_ri">
					<text>{{ jsonData.check_content }}</text>
				</view>
			</view>
			<view class="dec_li">
				<view class="dec_le">
					<label>*使用部门：</label>
				</view>
				<view class="dec_ri">
					<text>{{ jsonData.use_dept_name }}</text>
				</view>
			</view>
			<view class="dec_li">
				<view class="dec_le">
					<label>*审核部门：</label>
				</view>
				<view class="dec_ri">
					<text>{{ jsonData.audit_dept_name }}</text>
				</view>
			</view>
			<view class="dec_li">
				<view class="dec_le">
					<label>*计划开始时间：</label>
				</view>
				<view class="dec_ri">
					<text>{{ jsonData.permission_date }}</text>
				</view>
			</view>
			<view class="dec_li">
				<view class="dec_le">
					<label>*计划结束时间：</label>
				</view>
				<view class="dec_ri">
					<text>{{ jsonData.permission_end_date }}</text>
				</view>
			</view>
		</view>

		<!-- 检修认定 -->
		<view v-if="planlist.length > 0">
			<view class="criter_bt">
				<view class="line"></view>
				<text>检修认定</text>
			</view>
			<view v-for="(item, i) in planlist" :key="i" style="border-bottom: #F4F4F4 solid 10rpx;">
				<view class="dec_li dec_flex">
					<view class="dec_le">
						<label>*负责部门：</label>
					</view>
					<view class="dec_ri">
						<text>{{ item.major_dept }}</text>
					</view>
				</view>
				<view class="dec_li dec_flex">
					<view class="dec_le">
						<label>*主修人：</label>
					</view>
					<view class="dec_ri">
						<text>{{ item.major_name }}</text>
					</view>
				</view>
				<view class="dec_li dec_flex">
					<view class="dec_le">
						<label>*签名：</label>
					</view>
					<view class="dec_ri">
						<view class="sign-view">
							<image v-if="item.major_sign" :src="fileUrl + item.major_sign" @click="previewSign(item.major_sign)">
							</image>
						</view>
					</view>
				</view>

				<view class="dec_li dec_flex">
					<view class="dec_le">
						<label>*检修人：</label>
					</view>
					<view class="dec_ri">
						<text>{{ item.cooperate_user }}</text>
					</view>
				</view>
				<view class="dec_li dec_flex">
					<view class="dec_le">
						<label>*计划开始时间：</label>
					</view>
					<view class="dec_ri">
						<text>{{ item.plan_begin_date }}</text>
					</view>
				</view>
				<view class="dec_li dec_flex">
					<view class="dec_le">
						<label>*认定描述：</label>
					</view>
					<view class="dec_ri">
						<text>{{ item.confirm_desc }}</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 检修确认 -->
		<view v-if="confirmlist.length > 0">
			<view class="criter_bt">
				<view class="line"></view>
				<text>检修确认</text>
			</view>
			<view v-for="(item, i) in confirmlist" :key="i" style="border-bottom: #F4F4F4 solid 10rpx;">
				<view class="dec_li dec_flex">
					<view class="dec_le">
						<label>{{ showBuild ? "*负责人" : "*主修人" }}</label>
					</view>
					<view class="dec_ri">
						<text>{{ item.major_name }}</text>
					</view>
				</view>
				<view class="dec_li dec_flex">
					<view class="dec_le">
						<label>*签名确认：</label>
					</view>
					<view class="dec_ri">
						<view class="sign-view">
							<image v-if="item.major_sign" :src="fileUrl + item.major_sign" @click="previewSign(item.major_sign)">
							</image>
						</view>
					</view>
				</view>
				<view class="dec_li dec_flex">
					<view class="dec_le">
						<label>*值班工艺：</label>
					</view>
					<view class="dec_ri">
						<text>{{ item.duty_name }}</text>
					</view>
				</view>
				<view class="dec_li dec_flex">
					<view class="dec_le">
						<label>*签名确认：</label>
					</view>
					<view class="dec_ri">
						<view class="sign-view">
							<image v-if="item.monitor_sign" :src="fileUrl + item.monitor_sign"
								@click="previewSign(item.monitor_sign)"></image>
						</view>
					</view>
				</view>
				<!-- 	<view class="dec_li dec_flex">
					<view class="dec_le">
						<label>*许可检修时间：</label>
					</view>
					<view class="dec_ri">
						<text>{{item.permission_date}}</text>
					</view>
				</view> -->
				<view class="criter_bt">
					<view class="line"></view>
					<text>安全措施</text>
				</view>

				<view class="cfg-item" v-for="(jtem, j) in item.checklist" :key="j">
					<view class="cfg-title">风险分析</view>
					<view class="cfg-content">{{ jtem.risk_desc }}</view>
					<view class="cfg-title">安全措施</view>
					<view class="cfg-content">{{ jtem.safe_measure }}</view>
					<view>
						<text style="color: #0081FF;" v-if="jtem.result == 1">是</text>
						<text style="color: #ED1C24;" v-if="jtem.result == 2">否</text>
						<text style="color: #6A6A6A;" v-if="jtem.result == 3">不涉及</text>
					</view>
				</view>

				<view class="dec_li dec_flex">
					<view class="dec_le">
						<label>补充措施：</label>
					</view>
					<view class="dec_ri">
						<text>{{ item.supplement_desc }}</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 检修处理 -->
		<view v-if="handlelist.length > 0">
			<view class="criter_bt">
				<view class="line"></view>
				<text>检修处理</text>
			</view>

			<view v-for="(item, i) in handlelist" :key="i" style="border-bottom: #F4F4F4 solid 10rpx;">
				<view class="dec_li dec_flex">
					<view class="dec_le">
						<label>*处理类型：</label>
					</view>
					<view class="dec_ri">
						<text v-if="item.handle_type == 1">检修处理(阶段验收)</text>
						<text v-if="item.handle_type == 2">阶段验收</text>
						<text v-if="item.handle_type == 3">检修处理(最终验收)</text>
						<text v-if="item.handle_type == 4">最终验收</text>
						<text v-if="item.handle_type == 5">检修处理(终止）</text>
						<text v-if="item.handle_type == 6">检修处理(交班)</text>
						<text v-if="item.handle_type == 7">终止审核</text>
						<text v-if="item.handle_type == 8">终止驳回</text>
					</view>
				</view>
				<view class="dec_li dec_flex">
					<view class="dec_le">
						<label v-if="item.handle_type != 8">{{ showBuild ? "*负责人" : "*主修人" }}</label>
						<label v-if="item.handle_type == 8">{{ showBuild ? "*负责人" : "*主修人" }}</label>
					</view>
					<view class="dec_ri">
						<text v-if="item.handle_type != 8">{{ item.major_name }}</text>
						<text v-if="item.handle_type == 8">{{ item.handle_name }}</text>
					</view>
				</view>
				<view class="dec_li dec_flex" v-if="item.major_sign">
					<view class="dec_le">
						<label>*签名确认：</label>
					</view>
					<view class="dec_ri">
						<view class="sign-view">
							<image v-if="item.major_sign" :src="fileUrl + item.major_sign" @click="previewSign(item.major_sign)">
							</image>
						</view>
					</view>
				</view>
				<view class="dec_li dec_flex" v-if="item.user_sign">
					<view class="dec_le">
						<label v-if="[1, 3, 5, 6].includes(item.handle_type)">*配合人：</label>
						<label v-if="item.handle_type == 2">*验收人：</label>
						<label v-if="item.handle_type == 4">*验收人：</label>
					</view>
					<view class="dec_ri">
						<view class="sign-view">
							<image v-if="item.user_sign" :src="fileUrl + item.user_sign" @click="previewSign(item.user_sign)"></image>
						</view>
					</view>
				</view>

				<view class="dec_li dec_flex" v-if="item.technician_sign">
					<view class="dec_le">
						<label>*班长：</label>
					</view>
					<view class="dec_ri">
						<view class="sign-view">
							<image v-if="item.technician_sign" :src="fileUrl + item.technician_sign"
								@click="previewSign(item.technician_sign)"></image>
						</view>
					</view>
				</view>

				<view class="dec_li dec_flex">
					<view class="dec_le">
						<label v-if="item.handle_type != 8">*检修时间：</label>
						<label v-if="item.handle_type == 8">*处理时间：</label>
					</view>
					<view class="dec_ri">
						<text v-if="item.handle_type != 8">{{ item.overhaul_date }}</text>
						<text v-if="item.handle_type == 8">{{ item.handle_date }}</text>
					</view>
				</view>

				<view class="dec_li " v-if="item.handle_pics.length>0">
					<view class="dec_le">
						<label>拍照取证：</label>
					</view>
					<view class="dec_ri">
						<view class="pic-view">
							<view style="width: 70%; display: flex;">
								<view v-for="(jtem, j) in item.handle_pics" :key="j" style="margin: 10rpx;">
									<image :src="fileUrl + jtem.pic_url" class="detail_img"
										@click="previewImg(handlelist[handlelist.length - 1].handle_pics, j)"></image>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="dec_li">
					<view class="dec_le">
						<label v-if="item.handle_type == 1">今日工作情况</label>
						<label v-if="item.handle_type == 2">备注内容</label>
						<label v-if="item.handle_type == 3">今日工作情况</label>
						<label v-if="item.handle_type == 4">备注内容</label>
						<label v-if="item.handle_type == 5">今日工作情况</label>
						<label v-if="item.handle_type == 6">今日工作情况</label>
						<label v-if="item.handle_type == 7">备注内容</label>
						<label v-if="item.handle_type == 8">备注内容</label>
					</view>
					<view class="dec_ri">
						<text>{{ item.handle_desc }}</text>
					</view>
				</view>
				<view class="dec_li"
					v-if="item.handle_type == 1 || item.handle_type == 3 || item.handle_type == 5 || item.handle_type == 6">
					<view class="dec_le">
						<label>明日工作计划</label>
					</view>
					<view class="dec_ri">
						<text>{{ item.work_plan }}</text>
					</view>
				</view>

			</view>
		</view>


	</view>
</template>

<script>
import { getFormatDateTime } from '@/utils/date-util.js'
import { FILE_URL, getOverhaulInfo } from '@/api/maintenance/selfs.js'
export default {
	data () {
		return {
			active: 5,
			userName: '',
			userId: '',
			deptName: '',
			deptId: '',
			now: '',
			fileUrl: FILE_URL,
			imgPaths: [],
			overhaul_id: '',
			jsonData: {},
			// 认定
			planlist: [],
			// 确认
			confirmlist: [],
			handlelist: [],
			showBuild: false
		}
	},
	methods: {
		previewImg (imgs, index) {
			let pics = []
			for (let i = 0; i < imgs.length; i++) {
				pics[i] = this.fileUrl + imgs[i].pic_url
				console.log('PREVIEW', pics[i])
			}
			uni.previewImage({
				urls: pics,
				current: index
			})
		},

		previewSign (sign) {
			let imgs = []
			console.log('SIGN', sign)
			imgs.push(this.fileUrl + sign)
			console.log('SIGN', imgs)
			uni.previewImage({
				urls: imgs
			})
		},


		fetchDetailData () {
			let params = { overhaul_id: this.overhaul_id }
			uni.showLoading({
				title: '正在查询...'
			})
			getOverhaulInfo(params).then(res => {
				this.jsonData = res.datas
				this.showBuild = (this.jsonData.bill_type == 3)
				this.planlist = this.jsonData.planlist
				this.confirmlist = this.jsonData.confirmlist
				this.handlelist = this.jsonData.handlelist
			})
		},

		submitData () {
			if (this.signStr == '' || this.signStr2 == '') {
				uni.showToast({
					title: '请签名确认',
					icon: 'none'
				})
				return
			}
			if (this.acceptDate == '') {
				uni.showToast({
					title: '请选择验收时间',
					icon: 'none'
				})
				return
			}
			if (this.imgPaths.length == 0) {
				uni.showToast({
					title: '请先拍照取证',
					icon: 'none'
				})
				return
			}
			if (this.desc == '') {
				uni.showToast({
					title: '请填写验收描述',
					icon: 'none'
				})
				return
			}


			let params = {
				plan_id: this.plan_id, overhaul_id: this.overhaul_id,
				user_id: this.userId, pic: JSON.stringify(this.imgPaths),
				overhaul_date: this.acceptDate, handle_type: 2,
				major_sign: this.signPng, user_sign: this.signPng2,
				handle_desc: this.desc
			}
			uni.showLoading({
				title: '正在提交'
			})
			saveOverhaulVerify(params).then(res => {
				uni.$emit('accept_refresh')
				uni.showToast({
					title: '提交成功',
					icon: 'success',
					duration: 1500
				})
				setTimeout(function () {
					uni.navigateBack({
					})
				}, 500)
			})
		}
	},
	onLoad: function (e) {
		this.type = e.type
		this.userName = e.userName
		this.userId = e.userId
		this.deptName = e.deptName
		this.deptId = e.deptId
		this.overhaul_id = e.overhaul_id
		this.plan_id = e.plan_id
		this.fetchDetailData()
		this.now = getFormatDateTime()
		this.acceptDate = getFormatDateTime()
	}
}
</script>

<style>
page {
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	background-color: #fff
}

view {
	font-size: 28upx;
	line-height: inherit
}

.content {
	width: 100%;
	margin: 0 auto 80upx;
}

.example {
	width: 91%;
	margin: 20upx auto 20upx;
	padding: 0 30upx 0upx
}

.example-body {
	padding: 0 40upx
}

.buttn {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 5;
		padding: 20rpx;
		display: flex;
		justify-content: center;
		background-color: #FFF;
		
	}

	.buttn button {
		font-size: 30upx;
		background: #267dff;
		border-radius: 0;
		flex: 1;
		border-radius: 8rpx;
	}

.criter_bt {
	padding: 0 10px;
	height: 50px;
	background-color: #f7f7f7;
	font-weight: normal;
	display: flex;
	align-items: center;
	flex-direction: row;
}

.line {
	width: 8upx;
	height: 30upx;
	background: #267DFF;
	border-radius: 10upx;
	display: inline-block;
	vertical-align: middle;
}

.criter_bt text {
	padding-left: 10upx;
	vertical-align: middle;
	font-size: 32upx;
	color: #333333;
}

.dec_main {
	width: 94%;
}

.dec_li {
	width: 96%;
	margin: 30rpx 20rpx;
	overflow: hidden;
}

.dush_li {
	border-bottom: 1upx solid #f4f4f4;
	padding-bottom: 20upx;
}

.dec_le {
	width: 30%;
	float: left;
}

.dec_ri {
	float: left;
	width: 70%;
}

.dec_flex {
	min-height: 60rpx;
	display: flex;
	align-items: center;
}

.dec_li label {
	color: #267DFF;
	font-size: 30upx;
}

.dec_li text {
	color: #666666;
	font-size: 30upx;
}

.dec_li .inppu {
	font-size: 30upx;
}

.sign-view {
	display: flex;
	align-items: center;
}

.sign-view image {
	width: 150rpx;
	height: 60rpx;
	border: #d4ced8 solid 1rpx;
	border-radius: 5rpx;
	margin-right: 30rpx;
}

.sign-view text {
	width: 150rpx;
	height: 60rpx;
	border: #267DFF solid 1rpx;
	border-radius: 5rpx;
	color: #267DFF;
	font-size: 45rpx;
	text-align: center;
}

.signture {
	width: 0;
	height: 0;
}

.m-picker {
	margin-left: -25rpx;
}

.bottom-view {
	height: 100rpx;
	display: flex;
	align-items: center;
}

.detail_img {
	width: 150rpx;
	height: 150rpx;
	border: #f4f4f4 solid 1rpx;
}

.pic-view {
	display: flex;
	align-items: center;
}

.cfg-item {
	padding: 20rpx;
	border-bottom: 1upx solid #f4f4f4;
}

.cfg-title {
	font-size: 32rpx;
	color: #267DFF;
}

.cfg-content {
	font-size: 28rpx;
	margin-bottom: 10rpx;
}
</style>
